import { createStore, ModuleTree } from 'vuex'
import getters from './getters'

// 获取./modules下的所有模块
const modulesFiles: Record<string, any> = import.meta.globEager('./modules/**.ts')
const modules: ModuleTree<object> = {}
for (const modulePath in modulesFiles) {
  if (Object.prototype.hasOwnProperty.call(modulesFiles, modulePath)) {
    // './modules/app.js' => 'app'
    const moduleName = modulePath.replace(/^\.\/modules\/(.*)\.\w+$/, '$1')
    modules[moduleName] = modulesFiles[modulePath].default
  }
}
const store = createStore({
  modules,
  getters
})

export default store
